home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / fish / 726-750 / 744 / fo2 / sources_fo2 / optimize.c < prev    next >
C/C++ Source or Header  |  1995-03-18  |  6KB  |  268 lines

  1. #include "defs.h"
  2.  
  3. Prototype Organising(LONG    *buff1,struct DiskList *dlist,LONG    n);
  4. Prototype Datas(LONG    *buff1,LONG    n,struct DiskList *dlist);
  5. Prototype Preparing(LONG structsize,struct DiskList *adr);
  6. Prototype Length(struct DiskList *dlist);
  7. Prototype struct DiskList *whereB(WORD bloc);
  8. Prototype isinfo(BYTE *buff);
  9. Prototype Optimize();
  10. Prototype Inc(WORD *datafree);
  11. Prototype Nextdfree(WORD *datafree);
  12. Prototype ChangeBlocks();
  13.  
  14.  
  15. Organising(buff1,dlist,n)
  16. LONG    *buff1;
  17. struct DiskList *dlist;
  18. LONG    n;
  19.  
  20. {
  21.     switch (*buff1)
  22.     {
  23.         case 2L :
  24.         {
  25.             switch (*(buff1+127))
  26.             {
  27.  
  28.                 case 1L: /* RootBlock */
  29.                 {
  30.                     dlist=(struct DiskList *)Preparing(sizeof(struct SRootB),dsklist);
  31.                     dlist->dl_NextB=0;
  32.                     dlist->dl_Bloc=n;
  33.                     dlist->dl_Bloc2=n;
  34.                     dlist->dl_Data=0;
  35.                     dlist->dl_Type=3;
  36.                     dlist->dl_types.dl_type3.reserved1=0;
  37.                     dlist->dl_AdrB=buff1;
  38.                     break;
  39.                 }
  40.  
  41.                 case -3L: /* File Header Block */
  42.                 {
  43.                     dlist=(struct DiskList *)Preparing(sizeof(struct SFileHderB),dsklist);
  44.                     dlist->dl_NextB=0;
  45.                     dlist->dl_Bloc=n;
  46.                     dlist->dl_Bloc2=0;
  47.                     dlist->dl_Type=-1;
  48.                     dlist->dl_types.dl_type1.dl_Parent=((struct FileHeaderB*)buff1)->ParentDir;
  49.                     dlist->dl_types.dl_type1.dl_NextHash=((struct FileHeaderB*)buff1)->NextHash;
  50.                     dlist->dl_types.dl_type1.dl_Extension=((struct FileHeaderB*)buff1)->Extension;
  51.                     dlist->dl_AdrB=buff1;
  52.                     dlist->dl_Data=isinfo(buff1);
  53.                     break;
  54.                 }
  55.  
  56.                 case 2L: /* User Directory Block */
  57.                 {
  58.                     dlist=(struct DiskList *)Preparing(sizeof(struct SUserDirB),dsklist);
  59.                     dlist->dl_NextB=0;
  60.                     dlist->dl_Bloc=n;
  61.                     dlist->dl_Bloc2=0;
  62.                     dlist->dl_Type=4;
  63.                     dlist->dl_types.dl_type4.dl_Parent=((struct UserDirB*)buff1)->ParentDir;
  64.                     dlist->dl_types.dl_type4.dl_NextHash=((struct UserDirB*)buff1)->NextHash;
  65.                     dlist->dl_AdrB=buff1;
  66.                     dlist->dl_Data=isinfo(buff1);
  67.                     break;
  68.                 }
  69.  
  70.                 default :
  71.                 {
  72.                     if (FFS) { Datas(buff1,n,dlist); break;} else
  73.                     {
  74.                         dlist=(struct DiskList *)Preparing(sizeof(struct SUnknownB),dsklist);
  75.                         dlist->dl_NextB=0;
  76.                         dlist->dl_Bloc=n;
  77.                         dlist->dl_Bloc2=n;
  78.                         dlist->dl_Data=0;
  79.                         dlist->dl_Type=-2;
  80.                         dlist->dl_AdrB=buff1; 
  81.                         break;
  82.                     }
  83.                 }
  84.             }
  85.             break;
  86.         }
  87.  
  88.         case 16L: if (*(buff1+127)==-3) /* FileList Block */
  89.         {
  90.             dlist=(struct DiskList *)Preparing(sizeof(struct SFileListB),dsklist);
  91.             dlist->dl_NextB=0;
  92.             dlist->dl_Bloc=n;
  93.             dlist->dl_Bloc2=0;
  94.             dlist->dl_Data=0;
  95.             dlist->dl_Type=13;
  96.             dlist->dl_types.dl_type13.dl_FileHeader=((struct FileListB*)buff1)->ParentFH;
  97.             dlist->dl_types.dl_type13.dl_Extension=((struct FileListB*)buff1)->Extension;
  98.             dlist->dl_AdrB=buff1;
  99.             break;
  100.         }
  101.  
  102.         case 8L: /* Data Block */
  103.         {
  104.             Datas(buff1,n,dlist);
  105.             break;
  106.         }
  107.     
  108.         default :
  109.         {
  110.             if (FFS) {Datas(buff1,n,dlist); break;}
  111.             else
  112.             {
  113.             if (n==VarAdr->BitMap) break;
  114.             dlist=(struct DiskList *)Preparing(sizeof(struct SUnknownB),dsklist);
  115.             dlist->dl_NextB=0;
  116.             dlist->dl_Bloc=n;
  117.             dlist->dl_Bloc2=n;
  118.             dlist->dl_Data=0;
  119.             dlist->dl_Type=-2;
  120.             dlist->dl_AdrB=buff1;
  121.             break;
  122.         }
  123.         }
  124.     }
  125. }
  126.  
  127. Datas(buff1,n,dlist)
  128. LONG    *buff1;
  129. LONG    n;
  130. struct DiskList *dlist;
  131. {
  132.         dlist=(struct DiskList *)Preparing(sizeof(struct SDataB),dsklist);
  133.         dlist->dl_NextB=0;
  134.         dlist->dl_Bloc=n;
  135.         dlist->dl_Bloc2=0;
  136.         dlist->dl_Data=0;
  137.         dlist->dl_Type=8;
  138.         dlist->dl_types.dl_type8.dl_FileHeader=((struct DataB*)buff1)->HeaderKey;
  139.         dlist->dl_types.dl_type8.dl_NextData=((struct DataB*)buff1)->NextDataBlock;
  140.         dlist->dl_AdrB=buff1;
  141. }
  142.  
  143. Preparing(structsize,adr)
  144. LONG structsize;
  145. struct DiskList *adr;
  146.  
  147. {
  148. static struct DiskList *Sadr=0;
  149.  
  150.     if (Sadr==0 || (INIT & PREPARING) ) 
  151.     {
  152.         Sadr=adr;
  153.         INIT &= ~PREPARING; 
  154.     }
  155.     else adr=Sadr;
  156.  
  157.     if (adr->dl_NextB==0)
  158.     {
  159.         adr->dl_NextB=(struct DiskList *)AllocMem(structsize,MEMF_PUBLIC);
  160.         if (adr->dl_NextB==0 || (AvailMem(MEMF_PUBLIC) < 20480))
  161.         {
  162.             if (adr->dl_NextB) {FreeMem(adr->dl_NextB,structsize);
  163.                 adr->dl_NextB=0;}
  164.             puts("No mem for Preparing()\nFree a few mem an retry");
  165.             exit(0);
  166.         }
  167.         Sadr=adr->dl_NextB;
  168.         return(adr->dl_NextB);
  169.     }
  170.     else return(Preparing(structsize,adr->dl_NextB));
  171. }
  172.  
  173. Length(dlist)
  174. struct DiskList *dlist;
  175. {
  176. LONG length;
  177.     switch (dlist->dl_Type)
  178.     {
  179.         case -2: length=sizeof(struct SUnknownB); break;
  180.         case 13: length=sizeof(struct SFileListB); break;
  181.         case  8: length=sizeof(struct SDataB); break;
  182.         case  4: length=sizeof(struct SUserDirB); break;
  183.         case  3: length=sizeof(struct SRootB); break;
  184.         case -1: length=sizeof(struct SFileHderB); break;
  185.         case  0: length=sizeof(struct SinitB); break;
  186.         default : length=0; break;
  187.     }
  188.     return(length);    
  189. }
  190.  
  191. struct DiskList *whereB(bloc)
  192. WORD bloc;
  193. {
  194. struct DiskList *dlist;
  195.  
  196.     dlist=VarAdr->disklist;
  197.     while (dlist->dl_Bloc!=bloc && dlist!=0) dlist=dlist->dl_NextB;
  198.     return(dlist);
  199. }
  200. isinfo(buff)
  201. BYTE *buff;
  202. {
  203. BYTE name[30],length,n;
  204.  
  205.  
  206.     length=buff[108*4];
  207.     strncpy(name,buff+108*4+1,length);
  208.     name[length]=0;
  209.     for (n=length; n>=0 && name[n] != '.';n--);
  210.     if (stricmp(name+n,".info")==0)
  211.     return(1);
  212.     else return(0);
  213. }
  214.  
  215. Optimize()
  216. {
  217. WORD UDB[100];
  218. WORD i=1;
  219.  
  220.     UDB[0]=880;
  221.     UDB[1]=0;
  222.     /*printf("UDB[0] : %d\n",UDB[0]);*/
  223.     while (UDB[0])
  224.     {if (!arrange(UDB,&i)) break;} 
  225.  
  226. }
  227.  
  228.  
  229. Inc(datafree)
  230. WORD *datafree;
  231. {
  232. #ifdef DEBUG
  233. /*     printf("in Inc() datafree: %d\n",*datafree);*/
  234. #endif
  235.     if (*datafree<879) (*datafree)++; /* Ainsi 879 est donné mais pas 880 */
  236.     else
  237.     {
  238.         if (*datafree==879) *datafree=1759;
  239.         else (*datafree)--;
  240.     }
  241.     return(*datafree);
  242. }
  243.  
  244. Nextdfree(datafree)
  245. WORD *datafree;
  246. {
  247.     if (*datafree<879) return(*datafree+1); 
  248.     else
  249.     {
  250.         if ((*datafree+1)==880) return(1759);
  251.         else return(*datafree-1);
  252.     }
  253. }
  254.  
  255. ChangeBlocks()
  256. {
  257. struct DiskList *dlist;
  258.  
  259.     dlist=(struct DiskList *)VarAdr->disklist;
  260.  
  261.     while (dlist) 
  262.     {
  263.         dlist->dl_Bloc=dlist->dl_Bloc2;
  264.         dlist=dlist->dl_NextB;
  265.     }
  266.  
  267. }
  268.